import {mapMutations} from 'vuex'

export default {
    ...mapMutations([
        'upToken',
		'upUserInfo'
    ]),
	handlerChoose(){
		this.agree = !this.agree
	},
	//用户协议
	toUserAgreement(){
		uni.navigateTo({
			url: '/pages/publics/userAgreement'
		})
	},
	privacyAgreement(){
		uni.navigateTo({
			url: '/pages/publics/privacyAgreement'
		})
	},
	
    submitForm() {
        let that = this
        if (that.loading) {
            that.$toast.msg('请求中...', {
                icon: 1
            })
            return false
        }
        that.loading = true
			that.$httpRequest.request({
			    that: that,
			    url: 'h5/login',
			    params: that.formData,
			    success: res => {
			        that.loading = false
			        if (res.code === that.$httpConfig.SUCCESS_CODE) {
						that.$toast.msg('登录成功', {
						    icon: 1
						})
			            that.upToken(res.data)
						uni.setStorage({
							key: 'loginMode',
							data: 'phone'
						})
						that.getUserInfo()
                        let url = ''
                        url = '/pages/index/index'
						setTimeout(()=>{
							uni.switchTab({
							    url
							})
						},300)
			            
			        } else {
			            that.$toast.alert({
			                content: res.message,
			                callback: result => {

			                }
			            })
			        }
			    }
			})

    },
	getUserInfo() {
		let that = this
		that.$httpRequest.get({
			that: that,
			url: 'h5/info',
			params: {
	
			},
			success: res => {
				if (res.code === that.$httpConfig.SUCCESS_CODE) {
					that.upUserInfo(res.data)
					console.log(that.userInfo)
					// setTimeout(function () {
					// 		    uni.hideLoading();
					// 		}, 200);
				} else {
					that.upUserInfo({})
				}
			}
		},false)
	},
	toOtherLogin(){
		uni.navigateTo({
			url: '/pages/index/visitor'
		})
	},
	toLogin(){
		uni.navigateTo({
			url: '/pages/publics/login'
		})
	},
	toEmailLogin(){
		uni.navigateTo({
			url: '/pages/publics/emailLogin'
		})
	},
	toRegister(){
		uni.navigateTo({
			url: '/pages/publics/register'
		})
	},
	toEmailRegister(){
		uni.navigateTo({
			url: '/pages/publics/emailRegister'
		})
	},
	toReset(){
		uni.navigateTo({
			url: '/pages/publics/reset'
		})
	},
}
